| Conditions | 1 |
| Paths | 1 |
| Total Lines | 199 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | describe('Rest Proxy in Model', function() { |
||
| 2 | it('should save entity', function() { |
||
| 3 | var owner = Ext.create('Test.TestBundle.Entity.CarOwner', { |
||
|
|
|||
| 4 | name: 'James' |
||
| 5 | }); |
||
| 6 | var runned = false; |
||
| 7 | runs(function() { |
||
| 8 | owner.save({ |
||
| 9 | callback: function(record, operation, success) { |
||
| 10 | Test.TestBundle.Entity.CarOwner.load(record.getId(), { |
||
| 11 | callback: function(record) { |
||
| 12 | owner = record; |
||
| 13 | runned = true; |
||
| 14 | } |
||
| 15 | }); |
||
| 16 | } |
||
| 17 | }); |
||
| 18 | }); |
||
| 19 | waitsFor(function() { |
||
| 20 | return runned; |
||
| 21 | }); |
||
| 22 | runs(function() { |
||
| 23 | expect(owner.get('name')).toBe('James'); |
||
| 24 | }); |
||
| 25 | }); |
||
| 26 | it('should save existing entity with new hasMany association', function() { |
||
| 27 | var owner = Ext.create('Test.TestBundle.Entity.CarOwner', { |
||
| 28 | name: 'James' |
||
| 29 | }); |
||
| 30 | var runned = false; |
||
| 31 | runs(function() { |
||
| 32 | owner.save({ |
||
| 33 | callback: function(record, operation, success) { |
||
| 34 | owner.cars().add({ |
||
| 35 | name: 'Ford', |
||
| 36 | plateNumber: 'AA1234', |
||
| 37 | password: 'xx' |
||
| 38 | }, { |
||
| 39 | name: 'BMW', |
||
| 40 | plateNumber: 'ASF87654', |
||
| 41 | password: 'xx' |
||
| 42 | }); |
||
| 43 | owner.cars().sync({ |
||
| 44 | callback: function() { |
||
| 45 | Test.TestBundle.Entity.CarOwner.load(owner.getId(), { |
||
| 46 | callback: function(record) { |
||
| 47 | owner = record; |
||
| 48 | runned = true; |
||
| 49 | } |
||
| 50 | }); |
||
| 51 | } |
||
| 52 | }); |
||
| 53 | } |
||
| 54 | }); |
||
| 55 | }); |
||
| 56 | waitsFor(function() { |
||
| 57 | return runned; |
||
| 58 | }); |
||
| 59 | runs(function() { |
||
| 60 | expect(owner).not.toBeNull(); |
||
| 61 | expect(owner.cars().count()).toBe(2); |
||
| 62 | expect(owner.cars().first().get('name')).toBe('Ford'); |
||
| 63 | expect(owner.cars().first().getCarOwner()).toBe(owner); |
||
| 64 | }); |
||
| 65 | }); |
||
| 66 | it('should save existing entity with existing hasMany association', function() { |
||
| 67 | var owner = Ext.create('Test.TestBundle.Entity.CarOwner', { |
||
| 68 | name: 'James' |
||
| 69 | }); |
||
| 70 | var runned = false; |
||
| 71 | runs(function() { |
||
| 72 | owner.save({ |
||
| 73 | callback: function(record, operation, success) { |
||
| 74 | var car = Ext.create('Test.TestBundle.Entity.Car', { |
||
| 75 | name: 'Ford', |
||
| 76 | plateNumber: 'AA1234', |
||
| 77 | password: 'xx' |
||
| 78 | }); |
||
| 79 | car.save({ |
||
| 80 | callback: function(record) { |
||
| 81 | owner.cars().add(record); |
||
| 82 | owner.cars().sync({ |
||
| 83 | callback: function() { |
||
| 84 | owner.cars().first().getCarOwner({ |
||
| 85 | callback: function() { |
||
| 86 | runned = true; |
||
| 87 | } |
||
| 88 | }); |
||
| 89 | } |
||
| 90 | }); |
||
| 91 | } |
||
| 92 | }); |
||
| 93 | } |
||
| 94 | }); |
||
| 95 | }); |
||
| 96 | waitsFor(function() { |
||
| 97 | return runned; |
||
| 98 | }); |
||
| 99 | runs(function() { |
||
| 100 | expect(owner).not.toBeNull(); |
||
| 101 | expect(owner.cars().count()).toBe(1); |
||
| 102 | expect(owner.cars().first().get('name')).toBe('Ford'); |
||
| 103 | expect(owner.cars().first().getCarOwner().getData()).toEqual(owner.getData()); |
||
| 104 | }); |
||
| 105 | }); |
||
| 106 | it('should save existing entity with existing belongTo association', function() { |
||
| 107 | var car = Ext.create('Test.TestBundle.Entity.Car', { |
||
| 108 | name: 'Ford', |
||
| 109 | plateNumber: 'AA1234', |
||
| 110 | password: 'xx' |
||
| 111 | }); |
||
| 112 | var runned = false; |
||
| 113 | var car_owner_id; |
||
| 114 | runs(function() { |
||
| 115 | car.save({ |
||
| 116 | callback: function(record) { |
||
| 117 | var owner = Ext.create('Test.TestBundle.Entity.CarOwner', { |
||
| 118 | name: 'James Y' |
||
| 119 | }); |
||
| 120 | owner.save({ |
||
| 121 | callback: function(record) { |
||
| 122 | car.setCarOwner(record, { |
||
| 123 | callback: function() { |
||
| 124 | runned = true; |
||
| 125 | car_owner_id = car.get('car_owner_id'); |
||
| 126 | } |
||
| 127 | }); |
||
| 128 | } |
||
| 129 | }); |
||
| 130 | } |
||
| 131 | }); |
||
| 132 | }); |
||
| 133 | waitsFor(function() { |
||
| 134 | return runned; |
||
| 135 | }); |
||
| 136 | |||
| 137 | // Reload Car entity from REST proxy. Car_owner_id should still be there. |
||
| 138 | var runned1 = false; |
||
| 139 | runs(function() { |
||
| 140 | Test.TestBundle.Entity.Car.load(car.get('id'), { |
||
| 141 | callback: function(record) { |
||
| 142 | record.set('name', 'Audi'); |
||
| 143 | |||
| 144 | // Save and reload again. If car_owner_id was not there the belongsTo association is destroyed. |
||
| 145 | record.save({ |
||
| 146 | callback: function(record) { |
||
| 147 | Test.TestBundle.Entity.Car.load(car.get('id'), { |
||
| 148 | callback: function(record) { |
||
| 149 | car = record; |
||
| 150 | runned1 = true; |
||
| 151 | } |
||
| 152 | }); |
||
| 153 | } |
||
| 154 | }); |
||
| 155 | } |
||
| 156 | }); |
||
| 157 | }); |
||
| 158 | waitsFor(function() { |
||
| 159 | return runned1; |
||
| 160 | }); |
||
| 161 | |||
| 162 | runs(function() { |
||
| 163 | expect(car.getCarOwner()).not.toBeNull(); |
||
| 164 | expect(car.get('car_owner_id')).toBe(car_owner_id); |
||
| 165 | expect(car.getCarOwner().get('name')).toBe('James Y'); |
||
| 166 | expect(car.get('name')).toBe('Audi'); |
||
| 167 | }); |
||
| 168 | }); |
||
| 169 | it('should update entity', function() { |
||
| 170 | var car = Ext.create('Test.TestBundle.Entity.Car', { |
||
| 171 | name: 'Ford', |
||
| 172 | plateNumber: 'AA1234', |
||
| 173 | password: 'xx' |
||
| 174 | }); |
||
| 175 | var originalId; |
||
| 176 | var runned = false; |
||
| 177 | runs(function() { |
||
| 178 | car.save({ |
||
| 179 | callback: function(record) { |
||
| 180 | originalId = record.getId(); |
||
| 181 | record.set('name', 'BMW'); |
||
| 182 | record.save({ |
||
| 183 | callback: function(record) { |
||
| 184 | car = record; |
||
| 185 | runned = true; |
||
| 186 | } |
||
| 187 | }) |
||
| 188 | } |
||
| 189 | }) |
||
| 190 | }); |
||
| 191 | waitsFor(function() { |
||
| 192 | return runned; |
||
| 193 | }); |
||
| 194 | runs(function() { |
||
| 195 | expect(originalId).toBe(car.getId()); |
||
| 196 | expect(car.get('name')).toBe('BMW'); |
||
| 197 | }); |
||
| 198 | }) |
||
| 199 | }); |
||
| 200 | describe('Rest Proxy in Store', function() { |
||
| 289 | }); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.